<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" name="username" id="inp"><br>
    <span id="tips"> </span>
</body>

</html>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="./tools/ajax.js"></script>
<script>

    $("#inp").on("blur",async function(){
        $("#tips").html("")
        
        if(!this.value){
            $("#tips").html("请输入账号")
            return
        }

        


        // 向后端发起ajax请求
        let [err,results]=await ajax({
            type:"post",
            url:"http://localhost:3000/username",
            data:{
                username: $("#inp").val()
            }
        })



        // console.log([err,results]);
        if(err){
            return
        }


        if(results.status!=200){
            $("#tips").html(results.msg)
            return
        }

        $("#tips").html(results.msg)
        // -------------

    })


</script>